package com.example;

import org.junit.Test;

import java.util.Arrays;

public class Demo01 {

    /* {8, 3, 7, 12, 21} 降序--冒泡排序 */
    @Test
    public void test01() {
        int[] arr = {8, 3, 7, 12, 21};
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length -1 - i; j++) {
                if (arr[j] < arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }

    /* {8, 3, 7, 12, 21} 降序--选择排序 */
    @Test
    public void test02() {
        int[] arr = {8, 3, 7, 12, 21};
        for (int i = 0; i < arr.length - 1; i++){
            for(int j = i + 1; j < arr.length; j++){
                if (arr[i] < arr[j]){
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }

    public static void main(String[] args) {
        // 调用Demo02的几个方法
        // 普通方法由对象调用
        System.out.println(new Demo02().fun1(4));
        // 静态方法由类直接调用
        System.out.println(Demo02.fun2(10, 20));
        Demo02.fun3("", "");
    }
}
